const fs = require('fs');
const path = require('path');
const dbPath = path.join('/Users/liuzhongpei/Desktop/2007-b/9.29demo/app/db', '/userDb.json')
const addUserService = async (params) => {
    let myData = await JSON.parse(fs.readFileSync(dbPath, 'utf-8'))
    myData.push(params)
    await fs.writeFileSync(dbPath, JSON.stringify(myData), 'utf-8')
    return true
}
const deleteUserService = async (params) => {
    let myData = await JSON.parse(fs.readFileSync(dbPath, 'utf-8'))
    let arr = []
    await myData.forEach(item => {
        if (item.id != params) {
            arr.push(item)
        }
    })
    await fs.writeFileSync(dbPath, JSON.stringify(arr), 'utf-8')
    return true
}

module.exports = {
    addUserService,
    deleteUserService
}